package com.nbufe.controller;

import com.nbufe.domain.ResponseResult;
import com.nbufe.domain.dto.data.YearMonthRangeDto;
import com.nbufe.domain.vo.data.MonthRangeVo;
import com.nbufe.domain.vo.data.StageVo;
import com.nbufe.domain.vo.data.YearRangeVo;
import com.nbufe.service.DataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author LZH
 * @date 2023/4/7
 */
@Api(tags = "二氧化碳数据分析模块接口")
@RestController
@RequestMapping("/data")
public class DataController {

    @Resource
    private DataService dataService;

    @ApiOperation("获取指定年不同材料的1To12MonthCO2")
    @GetMapping("/listYearVaryMaterialOneTo12CO2")
    public ResponseResult listYearVaryMaterialOneTo12CO2(Integer year, Integer stage) {
        return ResponseResult.okResult(dataService.listYearVaryMaterialOneTo12CO2(year, stage));
    }

    @ApiOperation("获取各阶段总碳排放量")
    @GetMapping("/stageCO2")
    public ResponseResult queryTotalStageCO2() {
        Map<String, Double> map = dataService.queryTotalStageCO2();
        return ResponseResult.okResult(map);
    }

    @ApiOperation("获取指定年各阶段总碳排放量")
    @GetMapping("/stageYearCO2/{year}")
    public ResponseResult queryYearTotalStageCO2(@PathVariable Integer year) {
        Map<String, Double> map = dataService.queryTotalStageYearCO2(year);
        return ResponseResult.okResult(map);
    }

    @ApiOperation("根据年月范围计算各阶段总碳排放量")
    @GetMapping("/stageMonthRangeCO2")
    public ResponseResult queryStageMonthRangeCO2(YearMonthRangeDto dto) {
        List<List<MonthRangeVo>> lists = dataService.queryStageMonthRangeCO2(dto);
        return ResponseResult.okResult(lists);
    }

    @ApiOperation("根据年月范围计算年总碳排放量")
    @GetMapping("/yearRangeTotalCO2")
    public ResponseResult queryYearRangeTotalCO2(YearMonthRangeDto dto) {
        List<YearRangeVo> lists = dataService.queryYearRangeTotalCO2(dto);
        return ResponseResult.okResult(lists);
    }

    @ApiOperation("获取各阶段CO2占比")
    @GetMapping("/proportionStage")
    public ResponseResult getProportionStage() {
        return dataService.getProportionStage();
    }

    @ApiOperation("获取累计CO2排放量")
    @GetMapping("/totalCO2")
    public ResponseResult queryTotalCO2() {
        Double total = dataService.queryTotalCO2();
        return ResponseResult.okResult(total);
    }

    @ApiOperation("获取所有的年份")
    @GetMapping("/years")
    public ResponseResult getAllYears() {
        return dataService.getAllYears();
    }

    @ApiOperation("获取所有生产阶段")
    @GetMapping("/listStage")
    public ResponseResult listStage() {
        List<StageVo> stageList = dataService.listStage();
        return ResponseResult.okResult(stageList);
    }

    @ApiOperation("根据能源id获取指定工序")
    @GetMapping("/queryProcessByEmissionOrigin/{id}")
    public ResponseResult queryProcessByEmissionOrigin(@PathVariable Long id) {
        return dataService.queryProcessByEmissionOrigin(id);
    }

    @ApiOperation("查询所有工序碳排放")
    @GetMapping("/queryAllProcessEmissionOrigin")
    public ResponseResult queryAllProcessEmissionOrigin(Integer year) {
        return dataService.queryAllProcessEmissionOrigin(year);
    }

    @ApiOperation("查询近一个月的碳排放量")
    @GetMapping("/queryEmissionMonth")
    public ResponseResult queryEmissionMonth() {
        return dataService.queryEmissionMonth();
    }

    @ApiOperation("查询当年累计碳排放量")
    @GetMapping("/curYearEmission")
    public ResponseResult curYearEmission() {
        Double total = dataService.curYearEmission();
        return ResponseResult.okResult(total);
    }

    @ApiOperation("查询近12月碳排放量")
    @GetMapping("/query12MonthEmission")
    public ResponseResult query12MonthEmission() {
        return dataService.query12MonthEmission();
    }
}
